package everyday;

import org.junit.jupiter.api.Test;

public class T1616 {
    public boolean checkPalindromeFormation(String a, String b) {
        int len = a.length();
        int left = 0;
        boolean re = false;
        while (len / 2 >= left) {
            if (a.charAt(left) != b.charAt(len - left - 1)) {
                re = re || isPalindrome(a.substring(left, len - left));
                re = re || isPalindrome(b.substring(left, len - left));
                break;
            }
            left++;
        }
        if (left>len/2)return true;
        left = 0;
        while (len / 2 >= left){
            if (b.charAt(left)!=a.charAt(len-left-1)){
                re = re || isPalindrome(a.substring(left, len - left));
                re = re || isPalindrome(b.substring(left, len - left));
                break;
            }
            left++;
        }
        if (left>len/2)return true;
        return re;
    }

    public boolean isPalindrome(String s) {
        for (int i = 0; i < s.length() / 2; i++) {
            if (s.charAt(i) != s.charAt(s.length() - i - 1)) return false;
        }
        return true;
    }
    @Test
    public void test() {

        System.out.println(checkPalindromeFormation("xbdef","xecab"));
    }
}
